package com.gxa.web_admin.controller.operationscontroller;

import com.gxa.common.R;
import com.gxa.modules.pojo.Contract;
import com.gxa.modules.service.operationsservice.ContractService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/contract")
@Api(value = "合同管理模块",tags = "合同管理API")
public class ContractController {

    @Autowired
    ContractService contractService;


    @GetMapping("/selectForPage")
    @ApiOperation(value = "查询所有合同签订信息",notes = "根据传入信息查询合同订单信息",httpMethod = "GET", response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页面码",required = true,paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "size",value = "显示条数",required = true,paramType = "query",dataType = "int"),
            @ApiImplicitParam(name = "tenantName",value = "租户名称",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "buildName",value = "所属楼宇",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "roomName",value = "房间名称",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "contractType",value = "合同类型",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "contractStatus",value = "合同状态",paramType = "query",dataType = "String")

    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectForPage(@RequestParam int page,@RequestParam int size,String tenantName,
                           String buildName,String roomName,String property,String contractStatus)
    {
        return contractService.selectForPage(page,size,tenantName,buildName,roomName,property,contractStatus);
    }

    @GetMapping("/selectById")
    @ApiOperation(value = "查询合同签订详情",notes = "根据id查询合同签订详情",httpMethod = "GET", response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", required = true, paramType = "query", dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectById(@RequestParam int id)
    {
        return contractService.selectById(id);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加合同信息",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insert(@RequestBody Contract contract)
    {
        return contractService.insert(contract);
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "更新合同信息",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateById(@RequestBody Contract contract)
    {
        return contractService.updateById(contract);
    }
//
    @PostMapping("/deleteById")
    @ApiOperation(value = "删除合同信息",httpMethod = "POST", response = String.class)
    @ApiImplicitParam(name="id",value = "主键id")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteById(@RequestParam int id)
    {
        return contractService.deleteById(id);
    }
//
    @PostMapping("/deleteByPatch")
    @ApiOperation(value = "批量删除合同信息",httpMethod = "POST", response = String.class)
    @ApiImplicitParam(name="ids",value = "id数组")
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteByPatch(@RequestParam int[] ids)
    {
        return contractService.deleteByPatch(ids);
    }
}
